
/**		
 * 
 *	uk.co.lmfm.guppy.view.components.workspace.CreateWorkspacePopUp
 *	
 *	@version 1.00 | Jan 20, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.view.components.workspace 
{
	import uk.co.lmfm.guppy.view.components.core.PopupView;

	import com.bit101.components.Label;
	import com.bit101.components.PushButton;
	import com.bit101.components.Text;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;

	/**
	 * CreateWorkspacePopUp
	 */
	public class CreateWorkspacePopUp extends PopupView 
	{
		//	----------------------------------------------------------------
		//	CONSTANTS
		//	----------------------------------------------------------------

		private static const WIDTH : int = 280;
		private static const PROMPT : String = "Select a directory to configure as a workspace";

		//	----------------------------------------------------------------
		//	PRIVATE MEMBERS
		//	----------------------------------------------------------------

		private var _content : Sprite = new Sprite();
		private var _location : Text = new Text();
		private var _instructions : Label = new Label();
		private var _browse : PushButton = new PushButton();
		private var _workspace : File = new File();

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function CreateWorkspacePopUp()
		{
			_instructions.text = PROMPT + ":";
			_instructions.width = WIDTH;
			
			_location.width = WIDTH ;
			_location.height = 40;
			_location.y = _instructions.y + _instructions.height + 10;
			_location.editable = false;
			
			_browse.label = "Browse";
			_browse.x = (WIDTH >> 1) - (_browse.width >> 1);
			_browse.y = _location.y + _location.height + 10;
			_browse.addEventListener(MouseEvent.CLICK, onBrowseClicked);
			
			_content.addChild(_instructions);
			_content.addChild(_location);			_content.addChild(_browse);
			
			super("Create a new workspace", _content, "Create", "Cancel", false);
			
			_workspace.addEventListener(Event.SELECT, onWorkspaceSelected);
			
			_okButton.buttonMode = false;
			_okButton.mouseEnabled = false;
			_okButton.alpha = 0.6;
		}

		//	----------------------------------------------------------------
		//	EVENT HANDLERS
		//	----------------------------------------------------------------

		private function onBrowseClicked(event : MouseEvent) : void
		{
			_workspace.browseForDirectory(PROMPT);
		}

		private function onWorkspaceSelected(event : Event) : void
		{
			_location.text = _workspace.nativePath;
			
			_okButton.buttonMode = true;
			_okButton.mouseEnabled = true;
			_okButton.alpha = 1.0;
		}

		//	----------------------------------------------------------------
		//	PUBLIC ACCESSORS
		//	----------------------------------------------------------------

		public function get workspace() : File
		{
			return _workspace;
		}
	}
}
